public class 整数反转 {
    
    public static void main(String[] args) {
        

    }

    public static int reverse(int x) {
        
        StringBuilder builder;
        boolean minZreo = false;
        
        if(x >= 0){

            builder = new StringBuilder(String.valueOf(x));
            minZreo = false;
        } else {
            builder = new StringBuilder(String.valueOf(x).substring(1));
            minZreo = true;
        }

        //反转字符串
        String reverStr = builder.reverse().toString();

        if(minZreo){

            reverStr = "-"+reverStr;
        }

        try{


            return Integer.parseInt(reverStr);

        }catch(Exception e){

            return 0;
        }
    }
}
